package com.scau.os.course_manager.bean;

import com.scau.os.MemorySys.Hole;

import java.util.ArrayList;
import java.util.List;

public class PCB {

    public Register register=new Register();
    public String processID;

    private ProcessState state;

    public String blockEvent;
    public Hole hole;

    public int size;
    public boolean isIdle=false;

    private List<ValueChangeListener> stateChangeCallback=new ArrayList<>();

    public PCB() {
        processID=String.valueOf(hashCode());
    }

    public PCB(int id, ProcessState state, Hole hole) {
        this.processID = String.valueOf(id);;
        this.state = state;
        this.hole = hole;
    }

    public PCB(int id, ProcessState state) {
        this.processID = String.valueOf(id);
        this.state = state;
    }
    public String getProcessID() {
        return processID;
    }

    public Hole getHole() {
        return hole;
    }

    public void setHole(Hole hole) {
        this.hole = hole;
    }
    public void addStateChangeListener(ValueChangeListener r){
        stateChangeCallback.add(r);
    }
    public void deleteStateChangeListener(ValueChangeListener r){
        stateChangeCallback.remove(r);
    }

    public ProcessState getState() {
        return state;
    }

    public void setState(ProcessState state) {
        for (ValueChangeListener valueChangeListener:
             stateChangeCallback) {
            valueChangeListener.onChanged(this.state,state,processID);
        }
        this.state = state;
    }
}
